﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace EventWriter
{
    class XMLDOC
    {
        public static int writeXML()
        {
            XmlDocument XMLFile = new XmlDocument();
            XmlDeclaration declara1 = XMLFile.CreateXmlDeclaration("1.0", "utf-8", "yes");

            XmlElement root = XMLFile.CreateElement("scope");
            XMLFile.AppendChild(declara1);

            XmlElement country = XMLFile.CreateElement("country");
            XmlElement statement = XMLFile.CreateElement("statement");

            statement.InnerText = "ai";
            country.AppendChild(statement);
            statement = XMLFile.CreateElement("statement");
            statement.InnerText = "alliance_with";
            country.AppendChild(statement);
            statement = XMLFile.CreateElement("statement");
            statement.InnerText = "blockade";
            country.AppendChild(statement);
            statement = XMLFile.CreateElement("statement");
            statement.InnerText = "can_create_vassals";
            country.AppendChild(statement);
            root.AppendChild(country);


            XMLFile.AppendChild(root);

            XMLFile.Save("scope.xml");


            return 0;
        }


        public static int readXML(ref List<string> statements)
        {
            XmlDocument XMLFile = new XmlDocument();
            XMLFile.Load("scope.xml");
            XmlNodeReader reader = new XmlNodeReader(XMLFile);
            String tmp = "";
            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        tmp = reader.Name;
                        if (0 == string.Compare(tmp, "country", true)) break;
                        if (0 != string.Compare(tmp, "statement", true)) break;
                        break;
                    case XmlNodeType.Text:
                        tmp = reader.Value;
                        statements.Add(tmp);
                        break;
                }//switch end;
            }//while end;
            reader.Close();

            return 0;
        }
    }
}
